package com.gopay.bis.ipay.ebank.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.bis.ipay.ebank.operation.IpayDayEnd;
import com.gopay.bis.ipay.ebank.operation.IpayQuery;
import com.gopay.bis.ipay.ebank.operation.IpayRefund;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.ipay.ebank.IpayMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.BankService;
/**
 * 民生i支付接口实现
 * @IpayBankServiceImpl.java
 * @author lilili
 * @2016年7月8日 下午3:52:45  www.gopay.com.cn Inc.All rights reserved.
 */
public class IpayBankServiceImpl implements BankService{

	
	private ICertHelper ipayCertHelper;
	
	private IpayDayEnd ipayDayEnd;
	
	private IpayRefund iPayRefund; // 退款
	
	private IpayQuery iPayQuery; // 查询
	
	/** Logger for logging information. */
    protected Logger log = LoggerFactory.getLogger(this.getClass());
	

	@Override
	public Object sign(BaseMessage msg) throws GopayException {
		try {
            IpayMessage message = (IpayMessage) msg;
            String signMessage = (String) ipayCertHelper.sign(message);
            message.setSignMessage(signMessage);
            return message;
        } catch (Exception e) {
            log.error("ipay sign error:",e);
            return null;
        }
	}

	@Override
	public Object verify(BaseMessage msg) throws GopayException {
		try {
            IpayMessage message = (IpayMessage) msg;
            boolean isVerify = (Boolean) ipayCertHelper.verify(message);
            return isVerify;
        } catch (Exception e) {
            log.error("ipay verify error:",e);
            return null;
        }
	}
	
	@Override
	public Object dayend(Object arg0) throws GopayException {
		IpayMessage message = (IpayMessage) arg0;
		return ipayDayEnd.dayEnd(message);
	}

	@Override
	public Object query(Object base) throws GopayException {
	    IpayMessage message = (IpayMessage) base;
		return iPayQuery.queryOrder(message);
	}

    @Override
    public Object refund(Object obj) throws GopayException {
        IpayMessage message = (IpayMessage) obj;
        return iPayRefund.refund(message);
    }


	public void setIpayCertHelper(ICertHelper ipayCertHelper) {
		this.ipayCertHelper = ipayCertHelper;
	}


    public void setiPayRefund(IpayRefund iPayRefund) {
        this.iPayRefund = iPayRefund;
    }

    public void setiPayQuery(IpayQuery iPayQuery) {
        this.iPayQuery = iPayQuery;
    }

	public void setIpayDayEnd(IpayDayEnd ipayDayEnd) {
		this.ipayDayEnd = ipayDayEnd;
	}

}
